package com.koron.css2.newProjectCenter.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.newProjectCenter.task.PjTimerTask;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.apache.commons.lang3.StringUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.swan.bean.MessageBean;

import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: ；lwc
 * @Date: 2023/12/20/10:34
 * @Description:
 */
public class PjTimerExecutor implements ServerInterface {
    private static Logger logger = LoggerFactory.getLogger(PjTimerExecutor.class);
    private static final String KEY = "PJ_TIMER";
    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        Map<String, String> data = JsonUtils.objectToPojo(req.getData(), Map.class);
        if (StringUtils.isEmpty(data.get("company"))){
            return  MessageBean.create(Constant.MESSAGE_INT_FAIL, "参数不能为空", null);
        }
        String[] companyList = data.get("company").split(",", -1);
        try {
            new Thread(() -> {
                PjTimerTask timerTask = new PjTimerTask();
                // timerTask.timerTask(Arrays.asList(companyList));
            }).start();
        } catch (Exception e) {
            logger.error("执行失败", e);
        }
        return  MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "工程正在更新", null);
    }
}
